//
//  NSString+size.m
//  test
//
//  Created by john on 15/7/17.
//  Copyright (c) 2015年 john. All rights reserved.
//

#import "NSString+size.h"
#import <CommonCrypto/CommonDigest.h>
@implementation NSString (size)


-(CGSize)caculateSizeWithFont:(UIFont *)fnt MaxSize:(CGSize)maxSize{
    if (self == nil || [self length]==0) {
        return CGSizeZero;
    }
    NSMutableParagraphStyle *paragraphStyle=[[NSMutableParagraphStyle alloc]init];
    paragraphStyle.lineBreakMode=NSLineBreakByWordWrapping;
    NSDictionary *attributes=@{NSFontAttributeName:fnt,NSParagraphStyleAttributeName:paragraphStyle.copy};
    CGSize s=[self boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading | NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
    return s;
}

-(CGSize)sizeWithFnt:(UIFont *)font{
    return [self sizeWithAttributes:@{NSFontAttributeName : font}];
}


-(NSString *)md5
{
    const char *cStr=[self UTF8String];
    unsigned char result[16];
    CC_MD5(cStr, (UInt32)strlen(cStr), result);
    NSMutableString *hash=[NSMutableString string];
    for(int i=0;i<16;i++)
    {
        [hash appendFormat:@"%02X",result[i]];
    }
    return [hash lowercaseString];
    
}
@end
